package com.yl.auth.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yl.auth.entity.HugongfuwuBean;
import com.yl.auth.entity.HulidengjiBean;
import com.yl.auth.entity.HulixiangmuBean;
import com.yl.auth.service.HugongfuwuService;
import com.yl.auth.service.HulidengjiService;
import com.yl.auth.service.HulixiangmuService;
import com.yl.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 王帅洋
 * @datetime 2023/6/21 14:38
 * @description 类对象
 */
@Api(tags = "基础设置-护理项目")
@RestController
@RequestMapping("/admin/hulixiangmu")
public class HulixiangmuController {
    @Resource
    private HulixiangmuService hulixiangmuService;

    @Resource
    private HulidengjiService hulidengjiService;
    //护工服务
    @Resource
    private HugongfuwuService hugongfuwuService;
    @ApiOperation(value = "护理项目全查+分页")
    @GetMapping("/findAll/{page}/{limit}")
        public Result<IPage> findAll(@PathVariable Integer page, @PathVariable Integer limit, HulixiangmuBean hulixiangmuBean){
        Page page1 = new Page(page,limit);
        QueryWrapper<HulixiangmuBean> queryWrapper = new QueryWrapper<>();
        Page page2 = hulixiangmuService.page(page1,queryWrapper);
        return Result.ok(page2);
    }
    @ApiOperation(value = "新增护理项目")
    @PostMapping("/save")
    public Result save(@RequestBody HulixiangmuBean hulixiangmuBean){
        hulixiangmuService.save(hulixiangmuBean);
        return Result.ok();
    }
    @ApiOperation(value = "根据id查询护理项目--修改回显")
    @GetMapping("/get/{id}")
    public Result getById(@PathVariable Long id){
        HulixiangmuBean byId = hulixiangmuService.getById(id);
        return Result.ok(byId);
    }
    @ApiOperation(value = "删除护理项目")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Long  id){
        hulixiangmuService.removeById(id);
        return Result.ok();
    }
    @ApiOperation(value = "根据id修改护理项目")
    @PutMapping("/update")
    public Result update(@RequestBody HulixiangmuBean hulixiangmuBean){
        hulixiangmuService.updateById(hulixiangmuBean);
        return Result.ok();
    }

    @ApiOperation(value = "查询所有的护理等级----配置服务")
    @GetMapping("/getAlldengji")
    public Result getAlldengji(){
        List<HulidengjiBean> list = hulidengjiService.list();
        return Result.ok(list);
    }
    @ApiOperation(value = "查询已经选择的护理服务----配置服务")
    @GetMapping("/findfuwu/{id1}/{id2}")
    public Result findfuwu(@PathVariable Long id1,@PathVariable Long id2){
        List<HugongfuwuBean> list = hugongfuwuService.fuwuList(id1,id2);
        return Result.ok(list);
    }
    @ApiOperation(value = "查询没有选择的护理服务----配置服务")
    @PostMapping("/getxiangmuall/{id1}/{id2}")
    public Result getxiangmuall(@PathVariable Long id1,@PathVariable Long id2){
        List<HugongfuwuBean> list2 = hugongfuwuService.getxiangmuall(id1,id2);
        return Result.ok(list2);
    }
    @ApiOperation(value = "添加护理服务----配置服务")
    @PostMapping("/addfuwu/{id1}/{id2}")
    public Result addfuwu(@PathVariable Long id1,@PathVariable Long id2,@RequestBody List<Integer> ids){
        for (Integer id : ids) {
            hugongfuwuService.savefuwu(id,id1,id2);
        }
        return Result.ok();
    }
    @ApiOperation(value = "删除护理服务----配置服务")
    @DeleteMapping("/removeDataById/{id1}/{id2}/{id}")
    public Result removeDataById(@PathVariable Long id1,@PathVariable Long id2,@PathVariable Integer id){
        hugongfuwuService.removeDataById(id,id1,id2);
        return Result.ok();
    }
}
